package guowei.guliproduct.product.controller;

import java.util.Arrays;
import java.util.Map;

import guowei.guliproduct.product.vo.SpuInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import guowei.guliproduct.product.entity.SpuInfoEntity;
import guowei.guliproduct.product.service.SpuInfoService;
import guowei.common.utils.PageUtils;
import guowei.common.utils.R;



/**
 * spu信息
 *
 * @author guoguo
 * @email 1573746397@qq.com
 * @date 2023-05-21 17:38:07
 */
@Slf4j
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;


    @GetMapping("/{skuId}/spuInfo")
    public R getSpuInfoBySkuId(@PathVariable("skuId") Long skuId){
        SpuInfoEntity spuInfo = spuInfoService.getSpuInfoBySkuId(skuId);
        return R.ok().put("spuInfo",spuInfo);
    }

    /**
     * spu商品商家功能
     */
    @PostMapping("/{spuId}/up")
    public R listing(@PathVariable("spuId") Long spuId){
        spuInfoService.listingSpu(spuId);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = spuInfoService.queryPageByKeys(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:spuinfo:info")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存 发布商品时的所有信息
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:spuinfo:save")
    public R save(@RequestBody SpuInfoVo spuInfo){
//		spuInfoService.save(spuInfo);
        spuInfoService.fabushangpin(spuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:spuinfo:update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:spuinfo:delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
